Package edu.uky.ai.lp.ai
Class Continuation<T>
java.lang.Object
edu.uky.ai.lp.ai.Continuation<T>
- Type Parameters:
T- the type of value that this continuation will return
- Direct Known Subclasses:
Prover
public abstract class Continuation<T>
extends java.lang.Object
A continuation, sometimes called a generator, is like a function which can return multiple values in sequence. Each time the continuation returns a value, it pauses execution and waits to be called again. Subsequent calls will pick up where the last one left off.
A continuation has 4 important types of events in its lifecycle:
- CALL: The first time the continuation is invoked.
- REDO: Subsequent invocations.
- EXIT: Each time the continuation returns a value.
- FAIL: The final event, indicating there are no more values to be returned.
Continuations are implemented by extending this class and overriding the
run() method. Each time the continuation should return a value,
run() should call yield(Object). When run()
finishes, the continuation will FAIL.
- Author:
- Stephen G. Ware
-
Constructor Summary
Constructors Constructor Description Continuation() -
Method Summary
Modifier and Type Method Description Tcall()Invokes the continuation, picking up where the previous invocation (if any) stopped.booleandone()Indicates whether or not more CALLs can be made to this continuation.protected abstract voidrun()The actual work to be done by the continuation.protected voidyield(T value)This method is called each time the continuation should return a value.
-
Constructor Details
-
Continuation
public Continuation()
-
-
Method Details
-
done
public boolean done()Indicates whether or not more CALLs can be made to this continuation.- Returns:
- true if no more calls can be mode, false otherwise
-
call
Invokes the continuation, picking up where the previous invocation (if any) stopped.- Returns:
- the next value returned by the continuation, or null if this call resulted in FAIL
-
run
protected abstract void run()The actual work to be done by the continuation. -
yield
This method is called each time the continuation should return a value. The value to be returned is passed as a parameter. When this method is called, the continuation will pause until the next REDO event.- Parameters:
value- the value to be returned
-